Skip to content

Support multiple meshes in R2S calculations#3860

Merged
eepeterson merged 5 commits intoopenmc-dev:developfrom
paulromano:r2s-multi-mesh
Apr 28, 2026
Merged

Support multiple meshes in R2S calculations#3860
eepeterson merged 5 commits intoopenmc-dev:developfrom
paulromano:r2s-multi-mesh

Conversation

@paulromano
Copy link
Copy Markdown
Contributor

Description

This PR extends R2SManager to accept a list of meshes (as the domains argument), enabling mesh-based R2S calculations to use multiple non-overlapping meshes in a single workflow. Each element-material combination across all meshes is treated as an independent activation region. This can come in handy in a variety of situations:

  • Problems requiring varying spatial resolution in different regions
  • Activating two or more disconnected regions where a cell-based workflow is not sufficient
  • Activating a component that covers a large physical extent but is mostly empty (e.g., the vacuum vessel of a tokamak)

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Copy link
Copy Markdown
Contributor

@eepeterson eepeterson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the helpful improvement @paulromano. A number of small comments for your consideration, but nothing blocking.

Comment thread openmc/deplete/microxs.py
model : openmc.Model
OpenMC model object. Must contain geometry, materials, and settings.
domains : list of openmc.Material or openmc.Cell or openmc.Universe, or openmc.MeshBase, or openmc.Filter
domains : list of openmc.Material or openmc.Cell or openmc.Universe, or openmc.MeshBase, or openmc.Filter, or list of openmc.Filter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list feels like it's growing a bit long and having the general openmc.Filter and list of openmc.Filter in the documentation may be slightly misleading since not all Filter objects should be viable here.

Makes me wonder if it's worth creating an openmc.Domain enum-like type that does the type checking and validation for us and leveraging that here (and elsewhere potentially). The arguments to domains are defining spatial regions regardless of whether it is implicitly defined through something else like Material assignments. It might be nice to have a type or class that checks that what's passed is a valid way of defining some spatial domain.

It may be obvious what should and should not be allowed if someone is using this function, but it might help to be more explicit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the function signature, we actually do have a DomainTypes type alias that is used for the type hint. When I originally added that in, I opted not to put domains : DomainTypes in the docstring though because it is not as obvious to a user what that means, and I figured listing them out explicitly is, well, more explicit. However, the DomainTypes alias is nice as it simplifies the signature and would allow a type checker to validate arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this again, I think I misinterpreted your suggestion. Your proposed Domain is indeed different than the DomainTypes type alias (which is solely for type hinting). Adding Domain would be a bigger change that should probably be considered separately from the change here.

Comment thread openmc/deplete/microxs.py
domain_filters = [openmc.CellFilter(domains)]
elif isinstance(domains[0], openmc.Universe):
domain_filter = openmc.UniverseFilter(domains)
domain_filters = [openmc.UniverseFilter(domains)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do move forward with the above suggested abstraction this code could migrate.

Comment thread openmc/deplete/microxs.py Outdated
for flux_arr, rr_tally in zip(all_flux_arrays, rr_tallies):
flux = flux_arr
reaction_rates = rr_tally.get_reshaped_data()
reaction_rates = np.moveaxis(reaction_rates, 1, -1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be worth adding same comment here as above in the flux loop to make clear what is being aligned.

Comment thread openmc/deplete/r2s.py
----------
domains : openmc.MeshBase or Sequence[openmc.Cell]
The mesh or a sequence of cells that represent the spatial units over
domains : list of openmc.MeshBase or Sequence[openmc.Cell]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually seeing here that we use domains for a few different things, that may negate my previous comment, but I'll leave it for posterity.

Comment thread openmc/deplete/r2s.py
if mmv_file.exists():
self.results['mesh_material_volumes'] = \
openmc.MeshMaterialVolumes.from_npz(mmv_file)
mmv_files = sorted(neutron_dir.glob('mesh_material_volumes*.npz'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth including digit specifiers in the glob string to ensure what you're getting is indeed what you intend to sort. Same goes for below in the photon glob search.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, when I first wrote this I did have it with the digit specifiers but then changed it to the more generic expression for backward compatibility (since files created before this change won't have the digits appended).

@paulromano
Copy link
Copy Markdown
Contributor Author

@eepeterson your comments have been responded to/addressed. Let me know if you have further requests!

Copy link
Copy Markdown
Contributor

@eepeterson eepeterson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing left from me, thanks!

@eepeterson eepeterson merged commit 1116c4b into openmc-dev:develop Apr 28, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants